
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/09/2013 10:04:57
-- Generated from EDMX file: G:\Projets\MyEasyMenu\Menus\Menus\Model\DB\MenusModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Menus];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_IngredientIngredientPrix]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IngredientPrix] DROP CONSTRAINT [FK_IngredientIngredientPrix];
GO
IF OBJECT_ID(N'[dbo].[FK_IngredientTypeIngredient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ingredient] DROP CONSTRAINT [FK_IngredientTypeIngredient];
GO
IF OBJECT_ID(N'[dbo].[FK_IngredientPlat_Ingredient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IngredientPlat] DROP CONSTRAINT [FK_IngredientPlat_Ingredient];
GO
IF OBJECT_ID(N'[dbo].[FK_IngredientPlat_Plat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IngredientPlat] DROP CONSTRAINT [FK_IngredientPlat_Plat];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Ingredient]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ingredient];
GO
IF OBJECT_ID(N'[dbo].[IngredientPrix]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IngredientPrix];
GO
IF OBJECT_ID(N'[dbo].[Plat]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Plat];
GO
IF OBJECT_ID(N'[dbo].[IngredientType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IngredientType];
GO
IF OBJECT_ID(N'[dbo].[IngredientPlat]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IngredientPlat];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Ingredient'
CREATE TABLE [dbo].[Ingredient] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Libelle] nvarchar(100)  NOT NULL,
    [Cout] int  NOT NULL,
    [IngredientType_Id] int  NOT NULL
);
GO

-- Creating table 'IngredientPrix'
CREATE TABLE [dbo].[IngredientPrix] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [PrixUnitaire] float  NOT NULL,
    [DatePrix] datetime  NOT NULL,
    [Ingredient_ID] int  NOT NULL
);
GO

-- Creating table 'Plat'
CREATE TABLE [dbo].[Plat] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Libelle] nvarchar(500)  NOT NULL
);
GO

-- Creating table 'IngredientType'
CREATE TABLE [dbo].[IngredientType] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Libelle] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'IngredientPlat'
CREATE TABLE [dbo].[IngredientPlat] (
    [Ingredient_ID] int  NOT NULL,
    [Plat_ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Ingredient'
ALTER TABLE [dbo].[Ingredient]
ADD CONSTRAINT [PK_Ingredient]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'IngredientPrix'
ALTER TABLE [dbo].[IngredientPrix]
ADD CONSTRAINT [PK_IngredientPrix]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Plat'
ALTER TABLE [dbo].[Plat]
ADD CONSTRAINT [PK_Plat]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'IngredientType'
ALTER TABLE [dbo].[IngredientType]
ADD CONSTRAINT [PK_IngredientType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Ingredient_ID], [Plat_ID] in table 'IngredientPlat'
ALTER TABLE [dbo].[IngredientPlat]
ADD CONSTRAINT [PK_IngredientPlat]
    PRIMARY KEY NONCLUSTERED ([Ingredient_ID], [Plat_ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Ingredient_ID] in table 'IngredientPrix'
ALTER TABLE [dbo].[IngredientPrix]
ADD CONSTRAINT [FK_IngredientIngredientPrix]
    FOREIGN KEY ([Ingredient_ID])
    REFERENCES [dbo].[Ingredient]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IngredientIngredientPrix'
CREATE INDEX [IX_FK_IngredientIngredientPrix]
ON [dbo].[IngredientPrix]
    ([Ingredient_ID]);
GO

-- Creating foreign key on [IngredientType_Id] in table 'Ingredient'
ALTER TABLE [dbo].[Ingredient]
ADD CONSTRAINT [FK_IngredientTypeIngredient]
    FOREIGN KEY ([IngredientType_Id])
    REFERENCES [dbo].[IngredientType]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IngredientTypeIngredient'
CREATE INDEX [IX_FK_IngredientTypeIngredient]
ON [dbo].[Ingredient]
    ([IngredientType_Id]);
GO

-- Creating foreign key on [Ingredient_ID] in table 'IngredientPlat'
ALTER TABLE [dbo].[IngredientPlat]
ADD CONSTRAINT [FK_IngredientPlat_Ingredient]
    FOREIGN KEY ([Ingredient_ID])
    REFERENCES [dbo].[Ingredient]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Plat_ID] in table 'IngredientPlat'
ALTER TABLE [dbo].[IngredientPlat]
ADD CONSTRAINT [FK_IngredientPlat_Plat]
    FOREIGN KEY ([Plat_ID])
    REFERENCES [dbo].[Plat]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IngredientPlat_Plat'
CREATE INDEX [IX_FK_IngredientPlat_Plat]
ON [dbo].[IngredientPlat]
    ([Plat_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------